package com.yonglian.management.service.impl;

import com.yonglian.management.domain.ActivityStandard;
import com.yonglian.management.repository.ActivityStandardRepository;
import com.yonglian.management.service.ActivityStandardService;
import java.util.Optional;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * Service Implementation for managing {@link com.yonglian.management.domain.ActivityStandard}.
 */
@Service
@Transactional
public class ActivityStandardServiceImpl implements ActivityStandardService {

    private final Logger log = LoggerFactory.getLogger(ActivityStandardServiceImpl.class);

    private final ActivityStandardRepository activityStandardRepository;

    public ActivityStandardServiceImpl(ActivityStandardRepository activityStandardRepository) {
        this.activityStandardRepository = activityStandardRepository;
    }

    @Override
    public ActivityStandard save(ActivityStandard activityStandard) {
        log.debug("Request to save ActivityStandard : {}", activityStandard);
        return activityStandardRepository.save(activityStandard);
    }

    @Override
    public ActivityStandard update(ActivityStandard activityStandard) {
        log.debug("Request to update ActivityStandard : {}", activityStandard);
        return activityStandardRepository.save(activityStandard);
    }

    @Override
    public Optional<ActivityStandard> partialUpdate(ActivityStandard activityStandard) {
        log.debug("Request to partially update ActivityStandard : {}", activityStandard);

        return activityStandardRepository
            .findById(activityStandard.getId())
            .map(existingActivityStandard -> {
                if (activityStandard.getStandardName() != null) {
                    existingActivityStandard.setStandardName(activityStandard.getStandardName());
                }
                if (activityStandard.getCreateTime() != null) {
                    existingActivityStandard.setCreateTime(activityStandard.getCreateTime());
                }

                return existingActivityStandard;
            })
            .map(activityStandardRepository::save);
    }

    @Override
    @Transactional(readOnly = true)
    public Page<ActivityStandard> findAll(Pageable pageable) {
        log.debug("Request to get all ActivityStandards");
        return activityStandardRepository.findAll(pageable);
    }

    @Override
    @Transactional(readOnly = true)
    public Optional<ActivityStandard> findOne(Long id) {
        log.debug("Request to get ActivityStandard : {}", id);
        return activityStandardRepository.findById(id);
    }

    @Override
    public void delete(Long id) {
        log.debug("Request to delete ActivityStandard : {}", id);
        activityStandardRepository.deleteById(id);
    }
}
